package com.sevennotes.classtable.ui.pages.components

import androidx.compose.material.Slider
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.TransformOrigin
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.layout.layout
import androidx.compose.ui.unit.Constraints

@Composable
fun VerticalSlider(
  modifier: Modifier = Modifier,
  value: Float,
  min: Int,
  max: Int,
  onValueChange: (Float) ->Unit,
  onFinished: () -> Unit = {}
) {
  Slider(
    modifier = modifier
      .graphicsLayer {
        rotationZ = 270f
        transformOrigin = TransformOrigin(0f, 0f)
      }
      .layout { measurable, constraints ->
        val placeable = measurable.measure(
          Constraints(
            minWidth = constraints.minHeight,
            maxWidth = constraints.maxHeight,
            minHeight = constraints.minWidth,
            maxHeight = constraints.maxWidth,
          )
        )
        layout(placeable.height, placeable.width) {
          placeable.place(-placeable.width, 0)
        }
      },
    value = value,
    valueRange = min.toFloat()..max.toFloat(),
    onValueChange = onValueChange,
    onValueChangeFinished = onFinished,
  )
}